﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LightSO.Library.Common
{
    public class DatetimeHelper
    {
        /// <summary>
        /// 获取输入时间为一月的第几周
        /// </summary>
        /// <param name="day">当前时间</param>
        /// <param name="WeekStart">开始日，0=星期天，1=星期一，依此类推</param>
        /// <returns>返回周数</returns>
        public int WeekOfMonth(DateTime day, int WeekStart = 1)
        {                                                    
            DateTime FirstofMonth;
            FirstofMonth = Convert.ToDateTime(day.Date.Year + "-" + day.Date.Month + "-" + 1);
            int i = (int)FirstofMonth.Date.DayOfWeek;
            if (i == 0)
            {
                i = 7;
            }

            return (day.Date.Day + i - 2) / 7 + WeekStart;
        }  
    }
}
